# ============================================================================
# CPack template for LibSourcey
# ============================================================================

if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
set(CPACK_SET_DESTDIR TRUE)

# set(CPACK_PACKAGE_NAME "LibSourcey")
set(CPACK_PACKAGE_VENDOR "Sourcey")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "High-performance Networking and Media Libraries")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
set(CPACK_PACKAGE_CONTACT "Kam Low <hello@sourcey.com>")
set(CPACK_PACKAGE_VERSION_MAJOR "${LibSourcey_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${LibSourcey_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${LibSourcey_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${LibSourcey_VERSION}")

# arch
if(X86)
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
  set(CPACK_RPM_PACKAGE_ARCHITECTURE "i686")
elseif(X86_64)
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
  set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
elseif(ARM)
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf")
  set(CPACK_RPM_PACKAGE_ARCHITECTURE "armhf")
elseif(AARCH64)
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
  set(CPACK_RPM_PACKAGE_ARCHITECTURE "aarch64")
else()
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
  set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
endif()

if(CPACK_GENERATOR STREQUAL "DEB")
  set(LibSourcey_PACKAGE_ARCH_SUFFIX ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
elseif(CPACK_GENERATOR STREQUAL "RPM")
  set(LibSourcey_PACKAGE_ARCH_SUFFIX ${CPACK_RPM_PACKAGE_ARCHITECTURE})
else()
  set(LibSourcey_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR})
endif()

set(CPACK_PACKAGE_FILE_NAME "libsourcey-${LibSourcey_VERSION}-${LibSourcey_PACKAGE_ARCH_SUFFIX}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "libsourcey-${LibSourcey_VERSION}-${LibSourcey_PACKAGE_ARCH_SUFFIX}")

# rpm options
set(CPACK_RPM_COMPONENT_INSTALL TRUE)
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
set(CPACK_RPM_PACKAGE_URL "https://sourcey.com")
set(CPACK_RPM_PACKAGE_LICENSE "LGPL-2.1+")

# deb options
set(CPACK_DEB_COMPONENT_INSTALL TRUE)
# set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
# set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://sourcey.com")

# display names
set(CPACK_COMPONENT_LIBS_DISPLAY_NAME    "Libraries and data")
set(CPACK_COMPONENT_DEV_DISPLAY_NAME     "Development files")
set(CPACK_COMPONENT_SAMPLES_DISPLAY_NAME "Samples")
set(CPACK_COMPONENT_TESTS_DISPLAY_NAME   "Tests")

# depencencies
# set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)
# set(CPACK_DEBIAN_PACKAGE_DEPENDS "libx11-dev, libglu1-mesa-dev")
# set(CPACK_COMPONENT_LIBS_REQUIRED TRUE)
# set(CPACK_COMPONENT_DEV_DEPENDS libs)
# set(CPACK_COMPONENT_TESTS_DEPENDS libs)
# set(CPACK_COMPONENT_SAMPLES_DEPENDS libs)

set(CPACK_COMPONENT_LIBS_DESCRIPTION "LibSourcey")
set(CPACK_DEBIAN_COMPONENT_LIBS_NAME "libsourcey")

set(CPACK_COMPONENT_DEV_DESCRIPTION "Development files for LibSourcey")
set(CPACK_DEBIAN_COMPONENT_DEV_NAME "libsourcey-dev")

set(CPACK_COMPONENT_TESTS_DESCRIPTION "Accuracy and performance tests for LibSourcey")
set(CPACK_DEBIAN_COMPONENT_TESTS_NAME "libsourcey-tests")

set(CPACK_COMPONENT_SAMPLES_DESCRIPTION "Samples for LibSourcey")
set(CPACK_DEBIAN_COMPONENT_SAMPLES_NAME "libsourcey-samples")

include(CPack)

endif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
